package test4;

import java.io.*;
import java.net.Socket;

public class UploadClient {
    public static void main(String[] args) {
        BufferedOutputStream bos = null ;
        BufferedInputStream bis = null;

        try {
            Socket socket = new Socket("localhost",9898);
            bis = new BufferedInputStream(new FileInputStream(
                    "F:\\转换音视频\\大野克夫 - 「名探偵コナン」~メインテーマ.mp3"));

            bos = new BufferedOutputStream(socket.getOutputStream());

            byte[] buf = new byte[1024];
            int len = 0;
            while ((len = bis.read(buf))!=-1){
                bos.write(buf,0,len);
            }
            bos.flush();
            socket.shutdownOutput();
            //读取反馈
            InputStream is = socket.getInputStream();
           byte[] bytes = new byte[1024];

           int line = is.read(bytes);
           String client = new String(bytes,0,line);
            System.out.println(client);


        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                bos.close();
                bis.close();

            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

}
